﻿<UserControl x:Class="Deployment.Data.UI.Controls.Deploy.DeployEditorControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:steps ="clr-namespace:Deployment.Data.UI.Controls.Step"
             xmlns:tasks="clr-namespace:Deployment.Data.UI.Controls.Task"
             x:Name="EditorControl"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <DockPanel LastChildFill="True" Margin="8">
        <Grid DockPanel.Dock="Top">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <Label Grid.Row="0" Grid.Column="0"
                   Content="Deployment file path:"/>
            <TextBlock Grid.Row="0" Grid.Column="1"
                       TextWrapping="Wrap"
                       VerticalAlignment="Center"
                       x:Name="tbl_DeploymentFilePath"
                       Text="{Binding ElementName=EditorControl, Path=DeploymentFilePathText}"/>
            
            <Label Grid.Row="1" Grid.Column="0"
               Margin="2"
               Padding="2"
               VerticalAlignment="Center"
               Content="Deployment name:"/>

            <TextBox Grid.Row="1" Grid.Column="1"
                 Margin="2"
                 Padding="2"
                 VerticalAlignment="Center"
                 Text="{Binding Version}"/>
        </Grid>
        
        <Button DockPanel.Dock="Bottom"
                HorizontalAlignment="Right"
                Content="Save deployment"
                Click="SaveChanges_Click">
            <Button.Style>
                <Style>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding HasUnsavedChanges, Source=EditorControl}"
                                     Value="False">
                            <Setter Property="Button.IsEnabled" Value="False" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Button.Style>
        </Button>
        
        <GroupBox DockPanel.Dock="Top"
                  Header="Steps">
            <DockPanel Margin="4" LastChildFill="True">
                <steps:EditableStepList DockPanel.Dock="Top" x:Name="StepList" 
                                        DataContext="{Binding Path=Steps}" 
                                        Deployment="{Binding Path=DataContext, ElementName=EditorControl}"
                                        Environments="{Binding ElementName=EditorControl, Path=Environments}"/>
                
                <GroupBox DockPanel.Dock="Top"
                          Header="Step Task(s)">
                    <DockPanel LastChildFill="True">
                        <tasks:EditableTaskList CurrentStep="{Binding ElementName=StepList, Path=SelectedStep}" 
                                                Environments="{Binding ElementName=EditorControl, Path=Environments}"
                                                DataContext="{Binding ElementName=StepList, Path=SelectedStep.Tasks}">
                            <tasks:EditableTaskList.Style>
                                <Style>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding ElementName=StepList, Path=SelectedStep}"
                                                     Value="{x:Null}">
                                            <Setter Property="tasks:EditableTaskList.IsEnabled"
                                                    Value="False"/>
                                        </DataTrigger>
                                        
                                    </Style.Triggers>
                                </Style>
                            </tasks:EditableTaskList.Style>
                        </tasks:EditableTaskList>
                    </DockPanel>
                    
                </GroupBox>
            </DockPanel>
            
                
            
        </GroupBox>
        
    </DockPanel>
    
</UserControl>
